﻿using System;
using System.Windows.Forms;
using System.Data.OracleClient;
using TimeTableEasy.src.Core;
using TimeTableEasy.src.Database;

namespace TimeTableEasy
{
    public partial class User_Edit : Form
    {
        // 0 = ADD, 1 = MODIF , 2 = SUPPR
        private int status = 0;
        private int ID = 0;
        private int TypeAcc = 0;

        public User_Edit(String type)
        {
            InitializeComponent();

            switch (type)
            {
                case "add":
                    this.Text = "Ajouter un utilisateur";
                    editLbl.Text = "Ajouter un utilisateur";
                    addCampus.Text = "Ajouter";
                    campusList.Hide();
                    cursusList.Hide();
                    classList.Hide();
                    label4.Hide();
                    label5.Hide();
                    label10.Hide();
                    panel1.Hide();
                    lblPeriode.Hide();
                    cmbPeriode.Hide();
                    cmdAddCampus.Hide();
                    status = 0;

                    //CampusList Filler
                    OracleDataReader arrayCampus = OracleConnector.Query("SELECT CAM_NOM FROM campus order by (CAM_NOM)");

                    if (arrayCampus == null) return;

                    while (arrayCampus.Read())
                        campusList.Items.Add(arrayCampus.GetString(0));

                    arrayCampus.Dispose();

                    break;
                default:
                    break;
            }

        }

        public User_Edit(String type, int _ID, int _TypeAcc)
        {
            InitializeComponent();

            if (_ID != 0)
                ID = _ID;
            
            if (_TypeAcc != 0)
                TypeAcc = _TypeAcc;

            switch (type)
            {
                case "del":
                    this.Text = "Supprimer un utilisateur";
                    editLbl.Text = "Supprimer un utilisateur";
                    addCampus.Text = "Supprimer";
                    status = 2;
                    break;
                case "mod":
                    this.Text = "Modifier un utilisateur";
                    editLbl.Text = "Modifier un utilisateur";
                    addCampus.Text = "Modifier";
                    lblPeriode.Hide();
                    cmbPeriode.Hide();
                    classList.Hide();
                    label10.Hide();
                    cmbPeriode.Show();
                    status = 1;
                    accountType.Enabled = false;
                    this.Focus();

                    //Admin Global
                    if (TypeAcc == 0)
                    {
                        panel1.Hide();
                        cmdAddCampus.Hide();
                        accountType.SelectedIndex = TypeAcc;
                        OracleDataReader array = OracleConnector.Query("SELECT distinct(Ide_ID), Ide_Nom, Ide_Prenom, Ide_AdrRue, Ide_AdrCP, Ide_AdrVille, Ide_Mail, Ide_MDP, Ide_Telephone, Ide_DateNaissance FROM IDENTITE WHERE Ide_ID IN (SELECT Adm_Num FROM ADMINISTRATEUR) and Ide_ID = " + ID);

                        if (array == null) return;

                        array.Read();
                            
                        nameTxtBx.Text = array.GetString(1);
                        prenomTxtBx.Text = array.GetString(2);
                        txtRue.Text = array.GetString(3);
                        txtCP.Text = array.GetString(4);
                        txtVille.Text = array.GetString(5);
                        txtMail.Text = array.GetString(6);
                        txtPhone.Text = array.GetString(8);
                        birthDateTxtBox.Text = array.GetString(9);
                    }
                    else if (TypeAcc == 1)
                    {
                        panel1.Show();
                        cmdAddCampus.Show();
                        accountType.SelectedIndex = TypeAcc;
                        string campusname = "";
                        OracleDataReader array = OracleConnector.Query("SELECT distinct(Ide_ID), Ide_Nom, Ide_Prenom, Ide_AdrRue, Ide_AdrCP, Ide_AdrVille, Ide_Mail, Ide_MDP, Ide_Telephone, Ide_DateNaissance, Cam_Nom FROM IDENTITE, CAMPUS, CAMPUSMANAGER, CM_CAMPUS WHERE IDENTITE.Ide_ID = CAMPUSMANAGER.Cm_Num and CAMPUSMANAGER.Cm_Num = CM_CAMPUS.Ger_CmNum and CM_CAMPUS.Ger_CampusNum = CAMPUS.Cam_Num and Ide_ID IN (SELECT Cm_Num FROM CAMPUSMANAGER) and Ide_ID = " + ID);

                        if (array == null) return;

                        array.Read();
                        
                        nameTxtBx.Text = array.GetString(1);
                        prenomTxtBx.Text = array.GetString(2);
                        txtRue.Text = array.GetString(3);
                        txtCP.Text = array.GetString(4);
                        txtVille.Text = array.GetString(5);
                        txtMail.Text = array.GetString(6);
                        txtPhone.Text = array.GetString(8);
                        birthDateTxtBox.Text = array.GetString(9);
                        campusname = array.GetString(10);

                        //CampusList Filler
                        campusList.Items.Clear();
                        array = OracleConnector.Query("SELECT CAM_NOM FROM CAMPUS ORDER BY (CAM_NOM)");

                        if (array == null) return;

                        while (array.Read())
                            campusList.Items.Add(array.GetString(0));

                        campusList.SelectedItem = campusname;

                        addedCampusList.Items.Clear();
                        array = OracleConnector.Query("SELECT Cam_Nom FROM CAMPUS, CM_CAMPUS WHERE CAMPUS.Cam_Num = CM_CAMPUS.Ger_CampusNum and Ger_CmNum = " + ID);

                        if (array == null) return;

                        while (array.Read())
                            addedCampusList.Items.Add(array.GetString(0));
                    }
                    else if (TypeAcc == 2)
                    {
                        panel1.Hide();
                        cmdAddCampus.Hide();
                        accountType.SelectedIndex = TypeAcc;

                        OracleDataReader array = OracleConnector.Query("SELECT distinct(Ide_ID), Ide_Nom, Ide_Prenom, Ide_AdrRue, Ide_AdrCP, Ide_AdrVille, Ide_Mail, Ide_MDP, Ide_Telephone, Ide_DateNaissance FROM IDENTITE WHERE Ide_ID IN (SELECT Ens_Num FROM ENSEIGNANT) and Ide_ID = " + ID);

                        if (array == null) return;

                        array.Read();
                        
                        nameTxtBx.Text = array.GetString(1);
                        prenomTxtBx.Text = array.GetString(2);
                        txtRue.Text = array.GetString(3);
                        txtCP.Text = array.GetString(4);
                        txtVille.Text = array.GetString(5);
                        txtMail.Text = array.GetString(6);
                        txtPhone.Text = array.GetString(8);
                        birthDateTxtBox.Text = array.GetString(9);
                    }
                    else if (TypeAcc == 3)
                    {
                        panel1.Hide();
                        cmdAddCampus.Hide();
                        accountType.SelectedIndex = TypeAcc;
                        // Affichage des information de l'étudiant
                        string campusname = "", cursusname = "", periode = "";

                        OracleDataReader array = OracleConnector.Query("SELECT distinct(Ide_ID), Ide_Nom, Ide_Prenom, Ide_AdrRue, Ide_AdrCP, Ide_AdrVille, Ide_Mail, Ide_MDP, Ide_Telephone, Ide_DateNaissance, Cam_Nom, EC_CursusNom, Per_DateFin FROM IDENTITE, ETUDIANT, ETUDIANT_CURSUS, ETUDIANT_CAMPUS_PERIODE, CAMPUS, PERIODE WHERE IDENTITE.Ide_ID = ETUDIANT.Etu_Num and ETUDIANT.Etu_Num = ETUDIANT_CURSUS.EC_EtudiantNum and ETUDIANT.Etu_Num = ETUDIANT_CAMPUS_PERIODE.Ecp_EtudiantNum and ETUDIANT_CAMPUS_PERIODE.ECP_CampusNum = CAMPUS.Cam_Num and ETUDIANT_CAMPUS_PERIODE.Ecp_PeriodeNum = PERIODE.Per_Num and Ide_ID = " + ID);

                        if (array == null) return;

                        array.Read();
                        
                        nameTxtBx.Text = array.GetString(1);
                        prenomTxtBx.Text = array.GetString(2);
                        txtRue.Text = array.GetString(3);
                        txtCP.Text = array.GetString(4);
                        txtVille.Text = array.GetString(5);
                        txtMail.Text = array.GetString(6);
                        txtPhone.Text = array.GetString(8);
                        birthDateTxtBox.Text = array.GetString(9);
                        campusname = array.GetString(10);
                        cursusname = array.GetString(11);
                        periode = array.GetDateTime(12).ToString("dd/MM/yyyy");

                        //CampusList Filler
                        campusList.Items.Clear();
                        array = OracleConnector.Query("SELECT * FROM CAMPUS ORDER BY (CAM_NOM)");

                        if (array == null) return;

                        while (array.Read())
                            campusList.Items.Add(array.GetString(1));

                        campusList.SelectedItem = campusname;

                        //CursusList Filler
                        cursusList.Items.Clear();

                        array = OracleConnector.Query("SELECT CC_CURSUSNUM  FROM CAMPUS, CAMPUS_CURSUS  WHERE CAMPUS.CAM_NUM = CAMPUS_CURSUS.CC_CAMPUSNUM AND CAM_NOM = '" + campusList.SelectedItem.ToString() + "'");

                        if (array == null) return;

                        while (array.Read())
                            cursusList.Items.Add(array.GetString(0));
 
                        cursusList.SelectedItem = cursusname;

                        //periode List Filler
                        cmbPeriode.Items.Clear();

                        array = OracleConnector.Query("SELECT distinct(CAM_NOM), (PER_DATEFIN) FROM ETUDIANT_CAMPUS_PERIODE, PERIODE, CAMPUS WHERE CAMPUS.CAM_NUM = ETUDIANT_CAMPUS_PERIODE.ECP_CAMPUSNUM AND PERIODE.PER_NUM = ETUDIANT_CAMPUS_PERIODE.ECP_PERIODENUM AND CAM_NOM = '" + campusList.SelectedItem.ToString() + "' AND PER_DATEFIN >= Sysdate");

                        if (array == null) return;

                        while (array.Read())
                             cmbPeriode.Items.Add(array.GetDateTime(1).ToString("dd/MM/yyyy"));

                        cmbPeriode.SelectedItem = periode;
                    }
                    break;
            }
        }

        private void campusList_selectedIndexChanged(object sender, EventArgs e)
        {
            //Cursus List Filler
            cursusList.Items.Clear();
            cmbPeriode.Items.Clear();
            
            OracleDataReader array = OracleConnector.Query("SELECT CC_CURSUSNUM  FROM CAMPUS, CAMPUS_CURSUS  WHERE CAMPUS.CAM_NUM = CAMPUS_CURSUS.CC_CAMPUSNUM AND CAM_NOM = '" + campusList.SelectedItem.ToString());
            
            if (array == null) return;
            
            while (array.Read())
                cursusList.Items.Add(array.GetString(0));

            //periode List Filler
            array = OracleConnector.Query("SELECT distinct(CAM_NOM), (PER_DATEFIN) FROM ETUDIANT_CAMPUS_PERIODE, PERIODE, CAMPUS WHERE CAMPUS.CAM_NUM = ETUDIANT_CAMPUS_PERIODE.ECP_CAMPUSNUM AND PERIODE.PER_NUM = ETUDIANT_CAMPUS_PERIODE.ECP_PERIODENUM AND CAM_NOM = '" + campusList.SelectedItem.ToString() + "' AND PER_DATEFIN >= Sysdate");
            
            if (array == null) return;
            
            while (array.Read())
                cmbPeriode.Items.Add(array.GetDateTime(1).ToString("dd/MM/yyyy"));
        }

        //Gestion de l'affichage en fonction du type d'ajout.
        private void accountType_selectedIndexChanged(object sender, EventArgs e)
        {
            if (accountType.SelectedIndex == 0)
            {
                campusList.Hide();
                cursusList.Hide();
                classList.Hide();
                label4.Hide();
                label5.Hide();
                label10.Hide();
                cmbPeriode.Hide();
                lblPeriode.Hide();
                panel1.Hide();
                cmdAddCampus.Hide();
                //CampusList
                OracleDataReader array = OracleConnector.Query("SELECT CAM_NOM FROM CAMPUS");

                if (array == null) return;

                while (array.Read())
                    campusList.Items.Add(array.GetString(0));

            }
            if (accountType.SelectedIndex == 1)
            {
                campusList.Show();
                cursusList.Hide();
                classList.Hide();
                label4.Show();
                label5.Hide();
                label10.Hide();
                cmbPeriode.Hide();
                lblPeriode.Hide();
                panel1.Show();
                cmdAddCampus.Show();
            }
            if (accountType.SelectedIndex == 2)
            {
                campusList.Hide();
                cursusList.Hide();
                classList.Hide();
                label4.Hide();
                label5.Hide();
                label10.Hide();
                cmbPeriode.Hide();
                lblPeriode.Hide();
                panel1.Hide();
                cmdAddCampus.Hide();
            }
            if (accountType.SelectedIndex == 3)
            {
                campusList.Show();
                label4.Show();
                label5.Show();
                cursusList.Show();
                cmbPeriode.Show();
                lblPeriode.Show();
                cmdAddCampus.Hide();
                panel1.Hide();
            }

        }

        private void addCampus_Click(object sender, EventArgs e)
        {
            //Ajout d'un utilisateur
            if (status == 0)
            {
                //Controle des champs obligatoires

                if ((nameTxtBx.Text != null) || (prenomTxtBx.Text != "") || (birthDateTxtBox.Text != "") || (txtRue.Text != "") || (txtCP.Text != "") || (txtPhone.Text != "") || (txtMail.Text != "") || (txtVille.Text != ""))
                {
                    switch (accountType.SelectedIndex)
                    {
                        //Ajout d'un Administrateur Global
                        case 0:
                            OracleDataReader array7 = OracleConnector.Query("INSERT INTO IDENTITE (Ide_ID, Ide_Nom, Ide_Prenom, Ide_AdrRue, Ide_AdrCP, Ide_AdrVille, Ide_Mail, Ide_MDP, Ide_Telephone, Ide_DateNaissance) VALUES (Seq_identite.nextval, '" + nameTxtBx.Text + "' , '" + prenomTxtBx.Text + "', '" + txtRue.Text + "', '" + txtCP.Text + "', '" + txtVille.Text + "', '" + txtMail.Text + "', '" + Account.CalculateShaPassHash("MDP") + "', '" + txtPhone.Text + "', '" + birthDateTxtBox.Text + "')");
                            OracleDataReader array8 = OracleConnector.Query("INSERT INTO ADMINISTRATEUR VALUES (Seq_Identite.currval)");
                            OracleDataReader array9 = OracleConnector.Query("INSERT INTO TYPES VALUES (Seq_Identite.currval, " + 41 + ", sysdate");
                            if ((array7 != null) && (array8 != null) && (array9 != null))
                            { MessageBox.Show("Administrateur Ajouté!"); }
                            break;

                        //Ajout d'un Campus Director
                        case 1:
                                OracleDataReader array5 = OracleConnector.Query("INSERT INTO IDENTITE (Ide_ID, Ide_Nom, Ide_Prenom, Ide_AdrRue, Ide_AdrCP, Ide_AdrVille, Ide_Mail, Ide_MDP, Ide_Telephone, Ide_DateNaissance) VALUES (Seq_identite.nextval, '" + nameTxtBx.Text + "' , '" + prenomTxtBx.Text + "', '" + txtRue.Text + "', '" + txtCP.Text + "', '" + txtVille.Text + "', '" + txtMail.Text + "', '" + Account.CalculateShaPassHash("MDP") + "' , '" + txtPhone.Text + "', '" + birthDateTxtBox.Text + "')");
                                if (array5 == null) return;
                                OracleDataReader array30 = OracleConnector.Query("INSERT INTO TYPES VALUES (Seq_Identite.currval, " + 42 + ", sysdate)");
                                if (array30 == null) return;
                                OracleDataReader array31 = OracleConnector.Query("INSERT INTO CAMPUSMANAGER VALUES(Seq_Identite.currval)");
                                if (array31 == null) return;

                                bool nErr = false;
                                for (int i = 0; i < addedCampusList.Items.Count; i++)
                                {
                                    int numCampus = 0;

                                    OracleDataReader array33 = OracleConnector.Query("SELECT CAM_NUM FROM CAMPUS WHERE CAM_NOM = '" + addedCampusList.Items[i].ToString());

                                    if (array33 == null) return;

                                    array33.Read();
                                    
                                    numCampus = (int)array33.GetDecimal(0);

                                    OracleConnector.Query("INSERT INTO CM_CAMPUS VALUES(Seq_Identite.currval, " + numCampus + ")");

                                }
                                if ((array5 != null) && (array30 != null) && (array31 != null) && (nErr != false))
                                { MessageBox.Show("Directeur de Campus Ajouté!"); }
                                else { MessageBox.Show("Erreur lors de l'ajout"); }


                            break;

                        //Ajout d'un Professeur/Intervenant
                        case 2:
                            OracleDataReader array = OracleConnector.Query("INSERT INTO IDENTITE (Ide_ID, Ide_Nom, Ide_Prenom, Ide_AdrRue, Ide_AdrCP, Ide_AdrVille, Ide_Mail, Ide_MDP, Ide_Telephone, Ide_DateNaissance) VALUES (Seq_identite.nextval, '" + nameTxtBx.Text + "' , '" + prenomTxtBx.Text + "', '" + txtRue.Text + "', '" + txtCP.Text + "', '" + txtVille.Text + "', '" + txtMail.Text + "', '" + Account.CalculateShaPassHash("MDP") + "' , '" + txtPhone.Text + "', '" + birthDateTxtBox.Text + "')");
                            OracleDataReader array1 = OracleConnector.Query("INSERT INTO ENSEIGNANT VALUES (Seq_Identite.currval)");
                            OracleDataReader array11 = OracleConnector.Query("INSERT INTO TYPES VALUES (Seq_Identite.currval, " + 65 + ", sysdate");
                            if ((array != null) && (array1 != null) && (array11 != null))
                             MessageBox.Show("Intervenant Ajouté!"); 
                            break;

                        //Ajout d'un étudiant
                        case 3:
                            OracleDataReader array2 = OracleConnector.Query("INSERT INTO IDENTITE (Ide_ID, Ide_Nom, Ide_Prenom, Ide_AdrRue, Ide_AdrCP, Ide_AdrVille, Ide_Mail, Ide_MDP, Ide_Telephone, Ide_DateNaissance) VALUES (Seq_identite.nextval, '" + nameTxtBx.Text + "' , '" + prenomTxtBx.Text + "', '" + txtRue.Text + "', '" + txtCP.Text + "', '" + txtVille.Text + "', '" + txtMail.Text + "', '" + Account.CalculateShaPassHash("MDP") + "' , '" + txtPhone.Text + "', '" + birthDateTxtBox.Text + "')");
                            OracleDataReader array3 = OracleConnector.Query("INSERT INTO ETUDIANT VALUES (Seq_Identite.currval)");
                            OracleDataReader array12 = OracleConnector.Query("INSERT INTO ETUDIANT_CURSUS VALUES (Seq_Identite.currval, '" + cursusList.SelectedItem.ToString() + "')");

                            int numCampus2 = 0;

                            OracleDataReader array20 = OracleConnector.Query("SELECT CAM_NUM FROM CAMPUS WHERE CAM_NOM = '" + campusList.SelectedItem.ToString() + "'");

                            if (array20 == null) return;
                                    
                            numCampus2 = (int)array20.GetDecimal(0);
                            
                            int numPeriode = 0;
                            
                            array20 = OracleConnector.Query("SELECT PER_NUM FROM PERIODE WHERE PER_DATEFIN = TO_DATE('" + cmbPeriode.SelectedItem.ToString() + "','dd/mm/rrrr')");
                            
                            if (array20 == null) return;
                            
                            array20.Read();
                            
                            numPeriode = (int)array20.GetDecimal(0);
                            
                            array20 = OracleConnector.Query("INSERT INTO ETUDIANT_CAMPUS_PERIODE VALUES (" + numCampus2 + ", Seq_Identite.currval, " + numPeriode + ")");

                            if (array20 == null) return;
                            
                            if ((array2 != null) && (array3 != null) && (array12 != null) && (array20 != null))
                            {
                                MessageBox.Show("Etudiant Ajouté!");
                                campusList.Hide();
                                cursusList.Hide();
                                cmbPeriode.Hide();
                                ClearCtrl();                                
                            }
                            break;
                    }
                }
                else
                    MessageBox.Show("Les champs Nom, Prenom, Date de naissance doivent être remplis", "Informations manquantes");

            }
            //MODIFICATION
            bool nErr1 = false;
            if (status == 1)
            { 
                if ((ID != 0) || (nameTxtBx.Text != null) || (prenomTxtBx.Text != "") || (birthDateTxtBox.Text != "") || (txtRue.Text != "") || (txtCP.Text != "") || (txtPhone.Text != "") || (txtMail.Text != "") || (txtVille.Text != ""))
                {
                    //Modification de l'identite de l'utilisateur, peu importe son Type de comptes
                    OracleDataReader arrayID = OracleConnector.Query("UPDATE IDENTITE SET Ide_Nom = '" + nameTxtBx.Text + "', Ide_Prenom = '" + prenomTxtBx.Text + "', Ide_AdrRue = '" + txtRue.Text + "', Ide_AdrCP = '" + txtCP.Text + "', Ide_AdrVille = '" + txtVille.Text + "', Ide_Mail = '" + txtMail.Text + "', Ide_Telephone = '" + txtPhone.Text + "', Ide_DateNaissance = '" + birthDateTxtBox.Text + "' WHERE Ide_ID = " + ID + "");

                    if (arrayID == null)
                    { 
                        nErr1 = true;
                        return;
                    }
                    else { nErr1 = false; }

                }
                else
                    MessageBox.Show("Les champs Nom, Prenom, Date de naissance doivent être remplis", "Informations manquantes");
                
                //Modification des Campus d'un Campus Manager
                if (TypeAcc == 1)
                {
                    //On supprime tous les campus affilié a l'user
                    OracleDataReader array = OracleConnector.Query("DELETE FROM CM_CAMPUS WHERE Ger_CmNum = " + ID);

                    if (array == null)
                    {
                        nErr1 = true;
                        return;
                    }
                    else { nErr1 = false; }

                    //On ajoute les campus séléctionnés
                    for (int i = 0; i < addedCampusList.Items.Count; i++)
                    {
                        int numCampus = 0;
                        OracleDataReader array33 = OracleConnector.Query("SELECT CAM_NUM FROM CAMPUS WHERE CAM_NOM = '" + addedCampusList.Items[i].ToString() + "'");

                        if (array33 == null)
                        {
                            nErr1 = true;
                            return;
                        }
                        else { nErr1 = false; }

                        array33.Read();

                        numCampus = (int)array33.GetDecimal(0);

                        array33 = OracleConnector.Query("INSERT INTO CM_CAMPUS VALUES (" + ID + ", " + numCampus + ")");

                        if (array33 == null)
                        { 
                            nErr1 = true;
                            return;
                        }
                        else { nErr1 = false; }

                        if ((array33 != null) || (array33 != null))
                            nErr1 = false;
                    }
                    if (nErr1 == false)
                    {
                        MessageBox.Show("Utilisateur " + ID + " modifié", "Utilisateur Modifié");
                    }
                    else
                    {
                        MessageBox.Show("Erreur lors de la modification", "ERREUR");
                    }
                }
                //Modification Campus/Cursus/Periode d'un étudiant
                if (TypeAcc == 3)
                {
                    nErr1 = false;
                    //Modif Campus
                        //Recupération du num campus
                    int numCampus = 0;
                    string nomCampus = "";

                    if (campusList.SelectedItem == null)
                        nomCampus = campusList.Text;
                    else
                        nomCampus = campusList.SelectedItem.ToString();

                    OracleDataReader array33 = OracleConnector.Query("SELECT CAM_NUM FROM CAMPUS WHERE CAM_NOM = '" + nomCampus + "'");

                    if (array33 == null)
                    {
                        nErr1 = true;
                        return;
                    }
                    else nErr1 = false;

                    array33.Read();

                    numCampus = (int)array33.GetDecimal(0);

                    //Recuperation du numperiode

                    int numPeriode = 0;
                    
                    array33 = OracleConnector.Query("SELECT PER_NUM FROM PERIODE WHERE PER_DATEFIN = TO_DATE('" + cmbPeriode.SelectedItem.ToString() + "','dd/mm/rrrr')");

                    if (array33 == null) return;

                    array33.Read();

                    numPeriode = (int)array33.GetDecimal(0);

                    //Mise à jour Campus et Periode
                                OracleDataReader array = OracleConnector.Query("update ETUDIANT_CAMPUS_PERIODE set ECP_CampusNum = '" + numCampus + "' WHERE ECP_EtudiantNum = " + ID + " and ECP_PeriodeNum = " + numPeriode);
                                if (array == null)
                                {
                                    nErr1 = true;
                                    return;
                                }
                                else { nErr1 = false; }
                    //Mise à jour Cursus
                    OracleDataReader array1 = OracleConnector.Query("update ETUDIANT_CURSUS set EC_CursusNom = '" + cursusList.SelectedItem.ToString()+ "' WHERE EC_EtudiantNum = " + ID);
                    if (array1 == null)
                    {
                        nErr1 = true;
                        return;
                    }
                    else { nErr1 = false; }
                }
                if (nErr1 == false)
                    MessageBox.Show("Utilisateur " + ID + " modifié", "Utilisateur Modifié");
                else
                    MessageBox.Show("Erreur lors de la modification", "ERREUR");

            }

            //SUPPRESSION
            if (status == 2)
                nErr1 = false;
        }

        //Clear Function for Winform CTRL
        private void ClearCtrl()
        {
            nameTxtBx.Clear();
            prenomTxtBx.Clear();
            birthDateTxtBox.Clear();
            campusList.Items.Clear();
            cursusList.Items.Clear();
            txtRue.Clear();
            txtCP.Clear();
            txtPhone.Clear();
            txtMail.Clear();
            txtVille.Clear();
            cmbPeriode.Items.Clear();
        }

        //ajout d'un campus dans la liste
        private void cmdAddCampus_Click(object sender, EventArgs e)
        {
            addedCampusList.Items.Add(campusList.SelectedItem);
        }

        private void cmdDelselectedCampus_Click(object sender, EventArgs e)
        {

            for (int i = 0; i <= addedCampusList.Items.Count - 1; i++)
            {
                if (addedCampusList.GetItemCheckState(i) == CheckState.Checked)
                {
                    addedCampusList.Items.RemoveAt(i);
                    i--;
                }
            }
        }


    }
}

